package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.WakeUp;
import com.stylefeng.guns.modular.system.service.IWakeUpService;

/**
 * 唤醒控制器
 *
 * @author fengshuonan
 * @Date 2018-12-20 16:03:50
 */
@Controller
@RequestMapping("/wakeUp")
public class WakeUpController extends BaseController {

    private String PREFIX = "/system/wakeUp/";

    @Autowired
    private IWakeUpService wakeUpService;

    /**
     * 跳转到唤醒首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "wakeUp.html";
    }

    /**
     * 跳转到添加唤醒
     */
    @RequestMapping("/wakeUp_add")
    public String wakeUpAdd() {
        return PREFIX + "wakeUp_add.html";
    }

    /**
     * 跳转到修改唤醒
     */
    @RequestMapping("/wakeUp_update/{wakeUpId}")
    public String wakeUpUpdate(@PathVariable Integer wakeUpId, Model model) {
        WakeUp wakeUp = wakeUpService.selectById(wakeUpId);
        model.addAttribute("item",wakeUp);
        LogObjectHolder.me().set(wakeUp);
        return PREFIX + "wakeUp_edit.html";
    }

    /**
     * 获取唤醒列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return wakeUpService.selectList(null);
    }

    /**
     * 新增唤醒
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(WakeUp wakeUp) {
        wakeUpService.insert(wakeUp);
        return SUCCESS_TIP;
    }

    /**
     * 删除唤醒
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer wakeUpId) {
        wakeUpService.deleteById(wakeUpId);
        return SUCCESS_TIP;
    }

    /**
     * 修改唤醒
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(WakeUp wakeUp) {
        wakeUpService.updateById(wakeUp);
        return SUCCESS_TIP;
    }

    /**
     * 唤醒详情
     */
    @RequestMapping(value = "/detail/{wakeUpId}")
    @ResponseBody
    public Object detail(@PathVariable("wakeUpId") Integer wakeUpId) {
        return wakeUpService.selectById(wakeUpId);
    }
}
